home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 7
/
Apprentice-Release7.iso
/
Environments
/
PowerFantasm™ 4.19a
/
Beginners guide
/
GUIDE EXAMPLES
/
EXAMPLE9.S
< prev
next >
Wrap
Text File
|
1997-04-01
|
3KB
|
94 lines
********************************************************************************
*EXAMPLE 9 - CLEARING THE SCREEN *
*AUTHOR - STUART BALL JULY 94 *
*SCREEN MUST BE SET TO 256 COLOUR MODE FOR THIS EXAMPLE *
********************************************************************************
SCREENROW: EQU $0106 *WIDTH OF EACH SCREEN LINE
DEVICELIST: EQU $08A8 *THE ADDRESS OF DEVICELIST
gdPMap_offset: EQU 22
EXAMPLE8: MOVEM.L A5-A6,-(SP) *SAVE MAC WORLD
BSR INIT *INITIALISE OUR VARIABLES
BSR CLS *CLEAR THE SCREEN
MOVE.L #10,D0 *START X COORD OF LINE
MOVE.L #200,D1 *Y COORDINATE OF LINE
MOVE.B #20,D2 *COLOUR OF LINE
MOVE.L #600,D3 *END X COORDINATE OF LINE
BSR DRAW_H_LINE *DRAW A HORIZONTAL LINE
MOVEM.L (SP)+,A5-A6 *RESTORE MAC WORLD
RTS
************************END OF EXAMPLE 9***************************************
**INIT SETS UP OUR VARIABLES
INIT: LEA MY_VARS(PC),A6 *A6 IS OUR VARIABLE POINTER
MOVE.L DEVICELIST,A0
MOVE.L (A0),A0 *POINT TO DEVICELIST
MOVE.L A0,A1 *COPY ADDRESS OF DEVICE LIST
MOVE.L gdPMap_offset(A1),A1 *A1=POINTER TO GDPMAP
MOVE.L (A1),A1 *gdPMap IN A1
MOVE.W 10(A1),NUMB_OF_LINES(A6) *SAVE NUMBER OF LINES
MOVE.L (A1),VRAM_ADDR(A6) *SAVE VRAM ABSOLUTE ADDRESS
RTS
**CLS CLEARS THE MAC SCREEN TOTALLY
**PRESERVES ALL REGISTERS
CLS: MOVEM.L D0-D2/A1,-(SP) *SAVE REGS
CLR.L D0
CLR.L D1
CLR.L D2
MOVE.L VRAM_ADDR(A6),A1 *VRAM ADDRESS IN A1
MOVE.W NUMB_OF_LINES(A6),D0 *NUMBER OF LINES ON SCREEN
SUBQ.W #1,D0 *DBcc ALWAYS LOOPS ONE MORE THAN THE COUNT
MOVE.W SCREENROW,D1 *WIDTH IN BYTES OF EACH LINE
LSR.W #2,D1 *DIVIDE BY FOUR AS WERE CLEARING LONGS
SUBQ.W #1,D1 *DBRA ALWAYS LOOPS 1 MORE THAN THE COUNT!
MOVE.W D1,D2 *SAVE SIZE OF LINE(IN BYTES)
NEXT_LINE:
CLEAR_LINE: CLR.L (A1)+ *CLEAR THIS BYTE OF VRAM AND POINT TO NEXT
DBRA D1,CLEAR_LINE *CLEAR THIS LINE
MOVE.W D2,D1 *RESET BYTES/LINE COUNTER
DBRA D0,NEXT_LINE *CLEAR NEXT LINE
MOVEM.L (SP)+,D0-D2/A1 *RESTORE REGS
RTS
**DRAW_H_LINE DRAWS A HORIZONTAL LINE.
**NEEDS START X COORDINATE IN D0
** Y COORDINATE IN D1
** LINE COLOUR IN D2
** END X COORDINATE IN D3
DRAW_H_LINE: MOVE.L VRAM_ADDR(A6),A1 *FOR PLOT
DHL_LOOP: BSR PLOT *PLOT THIS PIXEL
ADD.W #1,D0 *INC X COORDINATE
CMP.W D3,D0 *COMPARE WITH END COORDINATE
BNE DHL_LOOP *IF NOT THERE YET, DRAW NEXT PIXEL
RTS
**PLOT IS A SUBROUTINE THATS PLOTS A PIXEL ON THE SCREEN IN THE COLOUR HELD IN D2
**NEEDS D0.W = X COORDINATE
** D1.W = Y COORDINATE
** D2.B = THE COLOUR
** A1 = VRAM BASE ADDRESS
**ALL REGISTERS REMAIN UNAFFECTED
PLOT: MOVEM.L D0-D3/A1,-(SP) *SAVE THE REGISTERS WE USE
MOVE.W SCREENROW,D3 *GET PHYSICAL LENGTH OF EACH SCREEN LINE
MULS D3,D1 *Y COORDINATE TIMES THE LENGTH OF EACH LINE
ADD.L D0,D1 *VRAM ADDRESS OF THIS PIXEL
ADD.L D1,A1 *ABSOLUTE ADDRESS OF THIS PIXEL
MOVE.B D2,(A1) *SET THE PIXEL TO THE COLOUR IN D2
MOVEM.L (SP)+,D0-D3/A1 *RESTORE THE REGS TO HOW THEY WERE
RTS *END OF SUBROUTINE PLOT
*********************************VARIABLES FOLLOW********************************
MY_VARS: DS.B 20 *SPACE FOR OUR VARIABLES
******************************OFFSETS INTO VARIABLES*****************************
NUMB_OF_LINES: EQU 0 .W NUMBER OF PHYSICAL LINES ON SCREEN
VRAM_ADDR: EQU 2 .L ABSOLUTE ADDRESS OF VRAM